home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu358.dms / pu358.adf / DonsGenies / Don'sGenies / BoxesToGrid.pprx < prev    next >
Text File  |  1992-08-06  |  3KB  |  109 lines

  1. /* This Genie snaps the corners of the boxes to the nearest grid point.
  2. Written by Don Cox  Aug 92   Copyright but freely usable for non-commercial purposes */
  3.  
  4. trace r
  5. signal on error
  6. signal on syntax
  7. address command
  8. call SafeEndEdit.rexx()
  9. call ppm_AutoUpdate(0)
  10. cr="0a"x
  11.  
  12. cpage = ppm_CurrentPage()
  13. counter=0
  14.  
  15. choice = ppm_Inform(2,"Which boxes?","All on page","Click to select")
  16.  
  17. select
  18. when choice = 1 then do
  19.     do forever
  20.         box=ppm_ClickOnBox("  Click on boxes to be repositioned")
  21.         if box=0 then break
  22.         counter=counter+1
  23.         boxes.counter=box
  24.         call ppm_SelectBox(box)
  25.         end
  26.     end
  27.  
  28. when choice = 0 then do
  29.     boxes.1 = ppm_PageFirstBox()
  30.     box = boxes.1
  31.     totalboxes = ppm_NumBoxes(cpage)
  32.     counter = totalboxes
  33.     do i=2 to totalboxes
  34.         box = ppm_PageNextBox(box)
  35.         boxes.i = box
  36.         end
  37.     end
  38.  
  39. otherwise exit_msg()
  40. end
  41.  
  42. if counter=0 then exit_msg("No boxes selected")
  43. currentunits=ppm_GetUnits()
  44. call ppm_SetUnits(2)
  45.  
  46. gridsize = ppm_GetGridSize()
  47. spacingY = word(gridsize,2) 
  48. spacingX = word(gridsize,1)
  49.  
  50.  
  51. call ppm_ShowStatus("  Tidying boxes...")
  52. do i=1 to counter
  53.     box=boxes.i
  54.  
  55.     Ypos = word(ppm_GetBoxPosition(box),2)
  56.     Xpos = word(ppm_GetBoxPosition(box),1)
  57.     oddbit = Ypos//spacingY
  58.     if oddbit<= spacingY/2 then Ypos = Ypos-oddbit
  59.     else Ypos = Ypos+spacingY-oddbit
  60.     oddbit = Xpos//spacingX
  61.     if oddbit<= spacingX/2 then Xpos = Xpos-oddbit
  62.     else Xpos = Xpos+spacingX-oddbit
  63.     call ppm_SetBoxPosition(box,Xpos,Ypos)
  64.  
  65.     width = word(ppm_GetBoxSize(box),1)
  66.     height = word(ppm_GetBoxSize(box),2)
  67.     oddbit = height//spacingY
  68.     if oddbit<= spacingY/2 then newheight = height-oddbit
  69.     else newheight = height+spacingY-oddbit
  70.     oddbit = width//spacingX
  71.     if oddbit<= spacingX/2 then newwidth = width-oddbit
  72.     else newwidth = width+spacingX-oddbit
  73.     call ppm_SetBoxSize(box,newwidth,newheight)   
  74.  
  75.     info = ppm_GetBoxInfo(box)
  76.     boxtype = word(info,1) 
  77.     if upper(boxtype) = "CLIP" | upper(boxtype) = "STRUCTURED" then do
  78.         scales = ppm_GetBoxScale(box)
  79.         Xscale = word(scales,1)
  80.         Yscale = word(scales,2)
  81.         call ppm_SetBoxScale(box, Xscale*(newwidth/width), Yscale*(newheight/height))
  82.         end
  83.  
  84.     end
  85.  
  86. call ppm_SetUnits(currentunits)
  87.  
  88. call exit_msg()
  89. end
  90.  
  91.  
  92.  
  93. error:
  94. syntax:
  95.     do
  96.     exit_msg("Genie failed due to error: "errortext(rc))
  97.     end
  98.  
  99. exit_msg:
  100.     do
  101.     parse arg message
  102.     if message ~= "" then
  103.     call ppm_Inform(1,message,"Resume")
  104.     call ppm_ClearStatus()
  105.     call ppm_AutoUpdate(1)
  106.     exit
  107.     end
  108.  
  109.